package com.health.mapp.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.health.db.model.RegisterSchedule;
import com.health.db.model.RegisterScheduleExample;
import com.health.db.service.order.IRegisterScheduleService;
import com.health.mapp.bean.Header;
import com.health.mapp.bean.QueryUserRegisterReq;
import com.health.mapp.bean.QueryUserRegisterResp;
import com.health.mapp.utils.Response;
import com.health.mapp.utils.ResultCode;

/**
 *查询已挂号
 * @author yuchong
 */
public class QueryUserRegisterImpl implements ActionInterface{

	@Autowired
	IRegisterScheduleService registerScheduleService;

    @Override
    public Response execute(Header header, Object reqBean) throws Exception {


    	QueryUserRegisterReq req = (QueryUserRegisterReq) reqBean;
    	QueryUserRegisterResp _resp = new QueryUserRegisterResp();
    	
    	String patientId=req.getPatientId();
    	String status= req.getStatus();
    	
    	String userId= req.getUserId();
    	
    	if (StringUtils.isEmpty(patientId)
    				&&StringUtils.isEmpty(userId)) {
    		
    		 _resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ERROR);
	         _resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ERROR_NOTE);
	         return _resp;
			
		}else{
		
			RegisterScheduleExample temp = new RegisterScheduleExample();
    		Integer pageNo=req.getPageNo();
    		Integer pageSize=req.getPageNum();
    		_resp.setPageNo(pageNo);
    		
    		if(null!=pageNo&&null!=pageSize){
    			temp.setOffset((pageNo.intValue()-1)*pageSize.intValue());
    			temp.setPageSize(pageSize.intValue());
    		}
    		
    		//查看状态
    		if (StringUtils.isNotEmpty(status)) {
    			temp.setStatus(Short.valueOf(status));
			}
    		
    		
    		//患者id
    		if (StringUtils.isNotEmpty(patientId)) {
    			temp.setPatientId(Long.valueOf(patientId));
			}
    		
    		//用户id
    		if (StringUtils.isNotEmpty(userId)) {
    			temp.setUserId(Long.valueOf(userId));
			}
    		
    		 List<RegisterSchedule> list = registerScheduleService.selectByExample(temp);
    		
    		_resp.setRegisterList(list);
			
			
		}
    	
		 _resp.setErrorCode(ResultCode.OPERATION_SUCCESS);
		 _resp.setErrorMsg(ResultCode.OPERATION_SUCCESS_NOTE);
        return _resp;
    }


	public IRegisterScheduleService getRegisterScheduleService() {
		return registerScheduleService;
	}

	public void setRegisterScheduleService(
			IRegisterScheduleService registerScheduleService) {
		this.registerScheduleService = registerScheduleService;
	}


    
    
    
}
